
#ifndef __APR_DOM_DOCUMENT_H
#define __APR_DOM_DOCUMENT_H

#include <apr_xml.h>

/** An XML parser/DOM document holding class that uses the built-in
 * XML parser in APR to parse and store XML documents. */
class APRDOMDocument
{
   public:
      APRDOMDocument(const char *buffer, int length, apr_pool_t *imp);
      APRDOMDocument(const char *filename, apr_pool_t *imp);
      APRDOMDocument(apr_pool_t *imp);
      ~APRDOMDocument();
      int addXMLData(const char *data, int datalen);
      int completeXMLParsing();
      apr_xml_elem *getRootNode();
      void createRootNode(const char *name);
      apr_xml_attr *getAttribute(apr_xml_elem *node, const char *attribname);
      const char *getAttributeValueString(apr_xml_elem *node, const char *attribname);
      void setAttribute(apr_xml_elem *elem, const char *key, const char *value);
      apr_xml_elem *createChildNode(apr_xml_elem *node, const char *name);
      apr_xml_elem *matchNodeInSubtree(apr_xml_elem *node, const char *name);
      apr_xml_elem *matchNodeInSubtree(apr_xml_elem *node, const char *name, const char *attribname);
      apr_xml_elem *matchNodeInSubtree(apr_xml_elem *node, const char *name, const char *attribname, const char *attribvalue);
      int readIn(const char *buffer, int length);
      int readIn(const char *filename);
      int writeOut(const char *filename);
      const char *getText();
      const char *getTextFromNode(apr_xml_elem *root);
   private:
      apr_xml_parser *initXMLParser(apr_pool_t *imp);
      /** Pointer to the document parser. If not in use, this is
       * NULL. */
      apr_xml_parser *docparser;
      /** Pointer to the DOM document. If the document has not been
       * parsed yet, this is NULL. */
      apr_xml_doc *docpntr;
      /** The memory pool for this instance. */
      apr_pool_t *mp;
      /** The parent memory pool that these constructors were
       * originally called with. */
      apr_pool_t *parent;
};

#endif
